import time
import requests
import execjs

def buy(id,token):
	times = int(time.time() * 1000)
	headers = {
		'Accept': 'application/json, text/plain, */*',
		'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
		'Authorization': token,
		'Cache-Control': 'no-cache',
		'Connection': 'keep-alive',
		'Content-Type': 'application/json',
		'Origin': 'https://m.shengqingqy.cn',
		'Pragma': 'no-cache',
		'Referer': 'https://m.shengqingqy.cn/',
		'Sec-Fetch-Dest': 'empty',
		'Sec-Fetch-Mode': 'cors',
		'Sec-Fetch-Site': 'same-site',
		'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1',
		'content-language': 'zh-CN',
	}
	json_data = {
		'productId': id,
		# 'randomCode': '8b748b936a9f23aa0e341ebea1003b45',
		'type': '3',
		'count': '1',
		'captchaTicket': '',
		'captchaRandstr': '',
		'score': 0,
		'firstBuyId': '',
		'ruleId': '',
		'payMethod': '4',
		'sign_appid': 'h5_23514861',
		'timestamp': times,
		# 'nonce': 'qyQsw8781896pGtMT',
		# 'sign': '8735e1ad2e3204776e2fdb8ea472eb17',
	}
	data = execjs.compile(open('./sign.js', 'r', encoding='utf-8').read()).call("getSign", json_data,'看你麻痹看')
	print(data)
	json_data['nonce'] = data['once']
	json_data['sign'] = data['md5']
	response = requests.post('https://api.shengqingqy.cn/order/app/order/submit', headers=headers, json=json_data).json()
	return response
# buy('1951472')